<?php
	defined( '_JEXEC' ) or die( 'Restricted access' );
	 
	//require_once( JPATH_COMPONENT.DS.'controller.php' );
	//if($controller = JRequest::getWord('controller')) {
	//    $path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
	//    if (file_exists($path)) {
	//        require_once $path;
	//    } else {
	//        $controller = '';
	//    }
	//}
	//JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_contratos'.DS.'tables');
	JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_contratos'.DS.'tables');
	$controllerName = JRequest::getCmd( 'c', 'contrato' );
	
	switch ($controllerName)
	{
		case 'proyecto':
			JSubMenuHelper::addEntry(JText::_('Contratos'), 'index.php?option=com_contratos');
			JSubMenuHelper::addEntry(JText::_('Proyectos'), 'index.php?option=com_contratos&c=proyecto',true);
			JSubMenuHelper::addEntry(JText::_('Tipo Contrato'), 'index.php?option=com_contratos');
			JSubMenuHelper::addEntry(JText::_('Propietario'), 'index.php?option=com_contratos');
			break;
		case 'tipo':
			JSubMenuHelper::addEntry(JText::_('Contratos'), 'index.php?option=com_contratos');
			JSubMenuHelper::addEntry(JText::_('Proyectos'), 'index.php?option=com_contratos');
			JSubMenuHelper::addEntry(JText::_('Tipo Contrato'), 'index.php?option=com_contratos&c=tipo',true);
			JSubMenuHelper::addEntry(JText::_('Propietario'), 'index.php?option=com_contratos');
			break;
		default:
			JSubMenuHelper::addEntry(JText::_('Contratos'), 'index.php?option=com_contratos',true);
			JSubMenuHelper::addEntry(JText::_('Proyectos'), 'index.php?option=com_contratos&c=proyecto');
			JSubMenuHelper::addEntry(JText::_('Tipo Contrato'), 'index.php?option=com_contratos&c=tipo');
			JSubMenuHelper::addEntry(JText::_('Propietario'), 'index.php?option=com_contratos');
			break;
	
	}	

	// Menu Helper 
	
	switch($controllerName)
	{
		default:
			$controllerName = 'contrato';
			
		case 'contrato':
		case 'proyecto':
			$task = JRequest::getCmd('task');
			if ($task == 'listproyectos') {
				$controllerName = 'proyecto';
			}
			require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' );
			$controllerName = 'ContratosController'.$controllerName;
			$controller = new $controllerName();
			$controller->execute( JRequest::getCmd('task') );
			$controller->redirect();
		
			//$classname = 'contratosController'.$controller;			
			//$controller = new $classname(); 
			//$controller->execute( JRequest::getCmd('task') ); 
			//$controller->redirect();
			break;
			
	}
	//$classname    = 'contratosController'.$controller;
	//$controller   = new $classname( );
	//$controller->execute( JRequest::getVar( 'task' ) );
	//$controller->redirect();
?>
